//
//  JddlotCell.m
//  PlayBall
//
//  Created by wangqian on 2017/3/16.
//
//
#define kCellId (@"cellId")

#import "JddlotCell.h"
#import "JdlotCollectionCell.h"
@interface JddlotCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property(nonatomic,strong)UICollectionView *collectionview;

@property(nonatomic,strong)NSMutableArray *alldataarr;

@end

@implementation JddlotCell
-(NSMutableArray *)alldataarr
{
    if (_alldataarr == nil) {
        
        _alldataarr = [[NSMutableArray alloc]init];
    }
    return _alldataarr;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //创建布局对象
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        //cell的大小
        layout.itemSize = CGSizeMake(SCREEN_WIDTH / 3, 80);
        
        //侧边距
        layout.minimumInteritemSpacing = 0;
        
        //排间距
        layout.minimumLineSpacing = 0;
        
        //上下左右的距离
        //layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
        self.collectionview = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200) collectionViewLayout:layout];
        self.collectionview.delegate = self;
        self.collectionview.dataSource = self;
        self.collectionview.showsVerticalScrollIndicator = NO;
        self.collectionview.showsHorizontalScrollIndicator = NO;
        self.collectionview.backgroundColor = [UIColor whiteColor];
        [self.collectionview registerClass:[JdlotCollectionCell class] forCellWithReuseIdentifier:kCellId];
        [self.contentView addSubview:self.collectionview];
    }
    return self;
}

//根据数据计算组
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
  
    return self.alldataarr.count;
    
}
//UICollectionView被选中时调用的方法
-( void )collectionView:( UICollectionView *)collectionView didSelectItemAtIndexPath:( NSIndexPath *)indexPath{

    int num;
    num = [[self.alldataarr objectAtIndex:indexPath.row] intValue];

    switch (num) {
        case 5:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"SSQ"];
            }
            //self.titlelabel.text = @"双色球";
        }
            break;
        case 70:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"11X5"];
            }
            //self.titlelabel.text = @"11选5";
        }
            break;
        case 6:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"FC3D"];
            }
            //self.titlelabel.text = @"福彩3D";
        }
            break;
        case 13:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"QLC"];
            }
            //self.titlelabel.text = @"7乐彩";
        }
            break;
        case 28:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"CQSSC"];
            }
            //self.titlelabel.text = @"时时彩";
        }
            break;
        case 62:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"11YDJ"];
            }
            //self.titlelabel.text = @"11夺运金";
        }
            break;
        case 39:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"CJDLT"];
            }
            //self.titlelabel.text = @"大乐透";
        }
            break;
        case 90:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"JCZQ"];
            }
            //self.titlelabel.text = @"竞猜足球";
        }
            break;

        case 45:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"BJDC"];
            }
            //self.titlelabel.text = @"北京单场";
        }
            break;
        case 91:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"JCLQ"];
            }
            //self.titlelabel.text = @"精彩篮球";
        }
            break;
        case 1:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"SFC"];
            }
            //self.titlelabel.text = @"胜负彩";
        }
            break;
        case 19:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"RXJ"];
            }
        }
            break;
        case 63:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"PL3"];
            }
        }
            break;
        case 64:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"PL5"];
            }
        }
            break;
        case 3:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"QXC"];
            }
        }
            break;
        case 96:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"LHC"];
            }
        }
            break;
        case 2:
        {
            if (_delegate && [_delegate respondsToSelector:@selector(pickdigitNumberButtonClicked:)]) {
                [_delegate pickdigitNumberButtonClicked:@"LHC"];
            }
        }
            break;
        default:
            break;
    }
    
}
//创建cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //复用cell
    JdlotCollectionCell *cell  = [collectionView dequeueReusableCellWithReuseIdentifier:kCellId forIndexPath:indexPath];
    //清空之前的（因为复用了之前的label ，不清空之前的数据会覆盖掉）
    int number;
    number = [[self.alldataarr objectAtIndex:indexPath.row] intValue];
    [cell number:number];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}
-(void)model:(NSMutableArray *)arrdata
{
    if (!arrdata || ![arrdata isKindOfClass:[NSArray class]] || arrdata.count == 0) {
        return;
    }
    NSMutableArray *arr = [[NSMutableArray alloc] init];
    for (arr in arrdata) {
        if (arr && [arr isKindOfClass:[NSArray class]]) {
            self.alldataarr = arr;
        }
    }
    [self.collectionview reloadData];
}
@end
